package com.unhz.taigu.interface_controllers.Insole;

import com.unhz.generator.pojo.ExpandImage;
import com.unhz.generator.pojo.InsoleImage;
import com.unhz.generator.pojo.Report;
import com.unhz.generator.utils.EmptyUtil;
import com.unhz.generator.utils.JsonResult;
import com.unhz.generator.vo.InsoleVo;
import com.unhz.taigu.service.ExpandImageService;
import com.unhz.taigu.service.InsoleImageService;
import com.unhz.taigu.service.InsoleService;
import com.unhz.taigu.service.ReportImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 沈佳庆
 * @Description: 样品详情接口
 * @Date: Created in 上午 9:49 2018/3/2 0002
 * @Modified By: V1.0.0
 */
@RestController
@RequestMapping("/IInsole")
public class IInsoleController {

    @Autowired
    private InsoleService insoleService;

    @Autowired
    private InsoleImageService insoleImageService;

    @Autowired
    private ExpandImageService expandImageService;

    @Autowired
    private ReportImageService reportImageService;

    /**
     * 商品详情
     * @param sampleId
     * @return
     */
    @RequestMapping("/details")
    public JsonResult details(@RequestParam(value = "sampleId",required = false) Integer sampleId){
        InsoleVo insole = insoleService.selectOneInsoleByInsoleId(sampleId);
        if(EmptyUtil.isEmpty(insole)){
            return JsonResult.failure("查询商品详情失败!");
        }
        List<InsoleImage> insoleImages = insoleImageService.selectInsoleImageList(sampleId);
        List<ExpandImage> expandImages = expandImageService.selectExpandImageList(sampleId);
        List<Report> reportList = reportImageService.selectReportImageList(sampleId);
        List<String> insoleImageUrl = new ArrayList<String>();
        List<String> expandImageUrl = new ArrayList<String>();
        List<String> reportUrl = new ArrayList<String>();
        for(InsoleImage insoleImage : insoleImages){
            /**中底图片路径**/
            insoleImageUrl.add(insoleImage.getImageUrl());
        }
        insole.setInsoleImageUrl(insoleImageUrl);
        for(ExpandImage expandImage : expandImages){
            /**展开图片路径**/
            expandImageUrl.add(expandImage.getImageUrl());
        }
        insole.setExpandImageUrl(expandImageUrl);
        for(Report report : reportList){
            //质检报告路径
            reportUrl.add(report.getReportUrl());
        }
        insole.setReportUrl(reportUrl);
        return JsonResult.success("查询商品详情成功!",insole);
    }


}
